import request from '@/utils/request'

/**
 * 重新分配
 * @param {*} data
 * @returns
 */
export function reallocate(data) {
  return request({
    url: '/api/v1/ctmIntendedCustomer/allot',
    method: 'PUT',
    data
  })
}
/**
 * 意向客户详情
 * @param {*} id
 * @returns
 */
export function potentialCustomerDetail(id) {
  return request({
    url: `/api/v1/ctmIntendedCustomer/${id}`,
    method: 'GET'
  })
}

/**
 * 新建意向客户
 * @param {*} data
 * @returns
 */
export function potentialCustomerAdd(data) {
  return request({
    url: '/api/v1/ctmIntendedCustomer',
    method: 'POST',
    data
  })
}
/**
 * 编辑意向客户
 * @param {*} data
 * @returns
 */
export function potentialCustomerEdit(data) {
  return request({
    url: '/api/v1/ctmIntendedCustomer',
    method: 'PUT',
    data
  })
}
/**
 * 下载导入模板
 * @returns
 */
export function downImportTemplate(filename) {
  return request({
    url: '/api/v1/ctmIntendedCustomer/exportImportModel',
    method: 'POST',
    responseType: 'blob'
  }).then(res => {
    const a = document.createElement('a')
    const tmp = URL.createObjectURL(res)
    a.href = tmp
    a.download = filename
    a.click()
    setTimeout(() => {
      URL.revokeObjectURL(tmp)
    }, 30 * 1000)
    return res
  })
}
/**
 * 查询客户经理
 * @param {*} managerAccount
 * @returns
 */
export function queryManagerByAccount(managerAccount) {
  const data = new FormData()
  data.append('pageFlag', false)
  const filtersRaw = [
    { id: 'enable', property: 'enable', value: '1', operator: '=' }
  ]
  filtersRaw.push({
    id: 'managerAccount',
    property: 'managerAccount',
    value: managerAccount,
    operator: '='
  })
  data.append('filtersRaw', JSON.stringify(filtersRaw))
  return request({
    url: '/api/v1/ctmInvestmentManager/page',
    method: 'POST',
    data
  }).then(res => {
    if (res.data.records && res.data.records.length > 0) {
      return res.data.records[0]
    }
    return Promise.reject(res)
  })
}
